{% extends "admin/base_site.html" %}
{% load i18n app_plugins satchmo_util %}

{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/dashboard.css{% endblock %}

{% block coltype %}colMS{% endblock %}

{% block bodyclass %}dashboard{% endblock %}

{% block breadcrumbs %}{% endblock %}

{% block extrahead %}
{{ block.super }}
<script type="text/javascript" src="../admin/jsi18n/"></script>
<script type="text/javascript">
var satchmo = satchmo || {};
satchmo.module_status = {};
l10n = {
	show : '{% trans '(show)' %}',
	hide : '{% trans '(hide)' %}'
}

satchmo.setup_toggle = function(elt) {
	var module = $(elt);
	module.click(function() { satchmo.toggle_module(this); });
	module.append(' <span class="status">' + l10n.hide + '</span>');
	var pid = module.parent().attr('id');
	satchmo.module_status[pid] = true;
}

satchmo.toggle_module = function(elt) {
	//console.log('toggle: ' + elt);
	var pid = $(elt).parent().attr('id');
	//console.log('pid: ' + pid);
	var content = $('#' + pid + ' .module-content');
	var span = $('#' + pid + ' h2 .status');
	if (satchmo.module_status[pid]) {
		content.slideUp('fast');
		span.text(l10n.show);
		var status = false;
	}
	else {
		content.slideDown('fast');
		span.text(l10n.hide);
		var status = true;
	}
	satchmo.module_status[pid] = status;
};

$(function() {
	$('#content-related h2.module-title').each(function() { 
		satchmo.setup_toggle(this);
	});
	satchmo.toggle_module($('#recent-actions-module h2'));
});
</script>
{% endblock %}

{% block content %}
<div id="content-main">

{% if app_list %}
    {% for app in app_list %}
        <div class="module">
        <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
        <caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption>
        {% for model in app.models %}
            <tr>
            {% if model.perms.change %}
                <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
            {% else %}
                <th scope="row">{{ model.name }}</th>
            {% endif %}

            {% if model.perms.add %}
                <td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'Add' %}</a></td>
            {% else %}
                <td>&nbsp;</td>
            {% endif %}

            {% if model.perms.change %}
                <td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
            {% else %}
                <td>&nbsp;</td>
            {% endif %}
            </tr>
        {% endfor %}
        </table>
        </div>
    {% endfor %}
{% else %}
    <p>{% trans "You don't have permission to edit anything." %}</p>
{% endif %}
</div>
{% endblock %}

{% block sidebar %}
<div id="content-related">
    <div class="module" id="recent-actions-module">
        <h2 class="module-title">{% trans 'Recent Actions' %}</h2>
		<div class="module-content">
        <h3>{% trans 'My Actions' %}</h3>
            {% load log %}
            {% get_admin_log 10 as admin_log for_user user %}
            {% if not admin_log %}
            <p>{% trans 'None available' %}</p>
            {% else %}
            <ul class="actionlist">
            {% for entry in admin_log %}
            <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">{% if not entry.is_deletion %}<a href="{{ entry.get_admin_url }}">{% endif %}{{ entry.object_repr|escape }}{% if not entry.is_deletion %}</a>{% endif %}<br /><span class="mini quiet">{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}</span></li>
            {% endfor %}
            </ul>
            {% endif %}
		</div>
    </div>

	{% include "shop/admin/order_sidebar.html" %}
	<div class="module" id="satchmo-helpers">
		<h2 class="module-title">{% trans "Admin Tools" %}</h2>
		<div class="module-content">
			<ul>
		    	<li>
					<a href="{% url satchmo_site_settings %}">{% trans "Edit Site Settings" %}</a><br/>
				</li>
				<li>
		    		<a href="{% url satchmo_admin_edit_inventory %}">{% trans 'Edit Inventory' %}</a><br/>
				</li>
				<li>
		    		<a href="{% url satchmo_admin_product_export %}">{% trans 'Export Product Defs' %}</a><br/>
				</li>
				<li>
		    		<a href="{% url satchmo_admin_variation_list %}">{% trans 'Product Variation Manager' %}</a><br/>
				</li>
				<li>
		    		<a href="{% url keyedcache_stats %}">{% trans 'Cache Status' %}</a><br/>
				</li>
				{% plugin_point "admin_tools" %}
			</ul>
		</div>
	</div>	
</div>
{% endblock %}
